using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Windows.Resources;
namespace MicroMsg.UI.Page
{
	public class LocalBulletinPage : BasePage
	{
		internal Grid LayoutRoot;
		internal WebBrowser webBrowser;
		private bool _contentLoaded;
		public LocalBulletinPage()
		{
			this.InitializeComponent();
		}
		protected override void OnPageIn(object[] object_0)
		{
			string text = "network_warning_EN.htm";
			if (R.isChineseCN())
			{
				text = "network_warning_CN.htm";
			}
			else
			{
				if (R.isChineseTW())
				{
					text = "network_warning_TW.htm";
				}
			}
			this.checkHtmlFile(text);
			this.webBrowser.add_LoadCompleted(new LoadCompletedEventHandler(this.webBrowser_loaded));
			this.webBrowser.set_Source(new Uri("html/" + text, 2));
		}
		private void webBrowser_loaded(object sender, EventArgs e)
		{
			Thickness margin = this.webBrowser.get_Margin();
			margin.set_Left(0.0);
			this.webBrowser.set_Margin(margin);
		}
		protected override void OnPageOut()
		{
		}
		private void checkHtmlFile(string fileName)
		{
			IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
			if (userStoreForApplication.FileExists("html/" + fileName))
			{
				return;
			}
			if (!userStoreForApplication.DirectoryExists("html"))
			{
				userStoreForApplication.CreateDirectory("html");
			}
			string text = "Resource/Html";
			StreamResourceInfo resourceStream = Application.GetResourceStream(new Uri(text + "/" + fileName, 2));
			using (BinaryReader binaryReader = new BinaryReader(resourceStream.get_Stream()))
			{
				byte[] array = binaryReader.ReadBytes((int)resourceStream.get_Stream().get_Length());
				using (BinaryWriter binaryWriter = new BinaryWriter(userStoreForApplication.CreateFile("html/" + fileName)))
				{
					binaryWriter.Write(array);
					binaryWriter.Close();
				}
				binaryReader.Close();
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Bulletin/LocalBulletinPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.webBrowser = (WebBrowser)base.FindName("webBrowser");
		}
	}
}
